package com.alks.function.controller.biocontrol.webWork;

import com.alibaba.excel.EasyExcel;
import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.WebLogger;
import com.alks.common.utils.MinIoUtil;
import com.alks.common.utils.excelUtils.ExcelUtils;
import com.alks.entity.data.entity.PcLotHead;
import com.alks.entity.data.page.PageRecord;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.request.biocontrol.webwork.LotProcRequest;
import com.alks.function.data.request.chengKong.PcLotHeadRequest;
import com.alks.function.data.vo.biocontrol.webWrok.DeliveryUpVo;
import com.alks.function.service.biocontrol.deptwork.ILotProcService;
import com.alks.function.service.chengKong.PcLotHeadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author MS
 * @since 2024/10/18上午11:32
 */
@RestController
@ApiRestController("/lot/proc")
@Api(value = "生控部", tags = "生控部-指令制作")
@Slf4j
public class LotProcController {
    @Autowired
    private ILotProcService service;
    @Autowired
    private PcLotHeadService lotHeadService;

    @WebLogger
    @PostMapping("/tempQuery")
    @ApiOperation(value = "表单查询", tags = "生控部-指令制作")
    public ResponseInfo tempQuery(@RequestBody PcLotHeadRequest request) {
        return lotHeadService.getStyleDetails(request);
    }

    @WebLogger
    @PostMapping("/back/season")
    @ApiOperation(value = "季节回显", tags = "生控部-指令制作")
    public ResponseInfo seasonBack(@RequestParam(required = false) String season) {
        List<String> seasonList = lotHeadService.seasonBack(season);
        return ResponseInfo.ok(seasonList);
    }

    @WebLogger
    @PutMapping("/delivery/update")
    @ApiOperation(value = "交期变更", tags = "生控部-指令制作")
    public ResponseInfo deliveryUp(MultipartFile file) {
        List<DeliveryUpVo> read = ExcelUtils.passRow(1).read(file, DeliveryUpVo.class);
        List<String> lotNoList = read.stream().map(DeliveryUpVo::getLotNo).collect(Collectors.toList());
        lotHeadService.lotCheck(lotNoList);
        /*整理数据*/
        List<PcLotHead> lotHeadList = read.stream().map(vo -> {
            PcLotHead lotHead = new PcLotHead();
            lotHead.setLotNo(vo.getLotNo());
            lotHead.setDeliveryDate(vo.getDeliveryDate());
            return lotHead;
        }).collect(Collectors.toList());
        /*调用写入*/
        lotHeadService.headListUpNotNull(lotHeadList);
        return ResponseInfo.ok();
    }

}